﻿using System;
namespace TI_BLE_HCI_ClientLib.DataEntities.Advertising
{
    public enum AdvertisingDataStructureTypeEnum
    {
        Flags = 0x01,
        IncompleteListOf16BitServiceClassUUIDs = 0x02,
        CompleteListOf16BitServiceClassUUIDs = 0x03,
        IncompleteListOf32BitServiceClassUUIDs = 0x04,
        CompleteListOf32BitServiceClassUUIDs = 0x05,
        IncompleteListOf128BitServiceClassUUIDs = 0x06,
        CompleteListOf128BitServiceClassUUIDs = 0x07,
        ShortenedLocalName = 0x08,
        CompleteLocalName = 0x09,
        TxPowerLevel = 0x0a,
        ClassOfDevice = 0x0d,
        SimplePairingHashC = 0x0e,
        SimplePairingHashC192 = 0x0e,
        SimplePairingRandomizerR = 0x0f,
        SimplePairingRandomizerR192 = 0x0f,
        DeviceID = 0x10,
        SecurityManagerTKValue = 0x10,
        SecurityManagerOutOfBandFlags = 0x11,
        SlaveConnectionIntervalRange = 0x12,
        ListOf16BitServiceSolicitationUUIDs = 0x14,
        ListOf32BitServiceSolicitationUUIDs = 0x1f,
        ListOf128BitServiceSolicitationUUIDs = 0x15,
        ServiceData = 0x16,
        ServiceData_16BitUUID = 0x16,
        ServiceData_32BitUUID = 0x20,
        ServiceData_128BitUUID = 0x21,
        PublicTargetAddress = 0x17,
        RandomTargetAddress = 0x18,
        Appearance = 0x19,
        AdvertisingInterval = 0x1a,
        LEBluetoothDeviceAddress = 0x1b,
        LERole = 0x1c,
        SimplePairingHashC256 = 0x1d,
        SimplePairingRandomizerR256 = 0x1e,
        ThreeDInformationData = 0x3d,
        ManufacturerSpecificData = 0xff
    }

    public abstract class AdvertisingDataStructure
    {
        private AdvertisingDataStructureTypeEnum _type;
        private byte[] _data;

        public byte[] Data
        {
            get { return _data; }
            set { _data = value; }
        }

        public AdvertisingDataStructureTypeEnum Type
        {
            get { return _type; }
            set { _type = value; }
        }

        public AdvertisingDataStructure(AdvertisingDataStructureTypeEnum type, byte[] data)
        {
            _type = type;
            _data = data;
        }

        public byte[] ToByteArray()
        {
            var adbuf = new byte[2 + _data.Length];

            adbuf[0] = (byte)(_data.Length+1);
            adbuf[1] = (byte)_type;
            
            Array.Copy(_data, 0, adbuf, 2, _data.Length);

            return adbuf;
        }
    }
}